<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用工合同')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="empformId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>姓名：</label>
                            <input autocomplete="off" type="text"  name="name" required/>
                        </li>
                        <li>
                            <label>部门：</label>
                            <input autocomplete="off" type="text"  name="department" required/>
                        </li>
                        <li>
                            <label>职务：</label>
                            <input autocomplete="off" type="text"  name="post" required/>
                        </li>
                        <li>
                            <label>合同类型：</label>
                            <select name="contractType" class="form-control" required>
                                <option value="">请选择</option>
                                <option value="1">劳动合同</option>
                                <option value="2">劳动协议</option>
                                <option value="3">聘用协议</option>
                            </select>
                        </li>
                        <li>
                            <label>起始日期：</label>
                            <div class="input-daterange input-group"><!--time-input-->
                                <input type="text" class="time-input" name="startBeginTime" placeholder="请填写日期"/>
                                <span>&nbsp;到&nbsp;</span>
                                <input type="text" class="time-input" name="startOverTime" placeholder="请填写日期"/>
                            </div>
                        </li>
                        <li>
                            <label>结束日期：</label>
                            <div class="input-daterange input-group">
                                <input type="text" class="time-input" name="endBeginTime" placeholder="请填写日期"/>
                                <span>&nbsp;到&nbsp;</span>
                                <input type="text" class="time-input" name="endOverTime" placeholder="请填写日期"/>
                            </div>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="status" class="form-control" required>
                                <option value="">请选择</option>
                                <option value="1">正常</option>
                                <option value="2">到期</option>
                                <option value="3">终止</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="query()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="hrm:employmentContract:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-success single disabled" onclick="$.operate.edit()" shiro:hasPermission="hrm:employmentContract:update">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="hrm:employmentContract:delete">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-info" onclick="$.table.importExcel('importTpl')" shiro:hasPermission="hrm:employmentContract:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="exportContract()" shiro:hasPermission="hrm:employmentContract:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-warning single disabled" onclick="openUpload()" shiro:hasPermission="hrm:employmentContract:upload">
                <i class="fa fa-upload"></i> 上传附件
            </a>
            <a class="btn btn-warning single disabled" onclick="downContract()" shiro:hasPermission="hrm:employmentContract:download">
                <i class="fa fa-download"></i> 下载附件
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">

    var prefix = ctx + "hrm/employmentContract";

    $(function () {
    })

    function openUpload(){
        var rows = $.table.selectColumns("ecId");
        if (rows.length != 1) {
            $.modal.alertWarning("请选择一条数据进行上传");
            return;
        }
        var ecId = rows.join();
        $.modal.openTab("上传附件", prefix + "/toUpload/"+ecId);
    }

    function downContract(){
        var rows = $.table.selectColumns("ecId");
        if (rows.length != 1) {
            $.modal.alertWarning("请选择一条数据进行下载");
            return;
        }
        var ecId = rows.join();
        $.modal.loading("正在下载，请稍后...");
        $.post(prefix+"/downloadContract",{"ecId":ecId},function (res) {
            if (res.code == web_status.SUCCESS) {
                window.location.href = prefix + "/downloadContract?fileName=" + encodeURI(res.data);
            } else if (res.code == web_status.WARNING) {
                $.modal.alertWarning(res.msg)
            } else {
                $.modal.alertError(res.msg);
            }
            $.modal.closeLoading();
        })
    }

    function exportContract(){
        var rows=$.table.selectColumns(table.options.uniqueId);
        var msg = "确定导出所有" + table.options.modalName + "吗？"
        if(rows.length!=0){
            msg = "确定导出勾选的"+rows.length+"条数据吗？"
        }
        $.modal.confirm(msg, function() {
            var params = $("#" + table.options.id).bootstrapTable('getOptions');
            var dataParam = $("#empformId").serializeArray();
            dataParam.push({ "name": "orderByColumn", "value": params.sortName });
            dataParam.push({ "name": "isAsc", "value": params.sortOrder });
            if(rows.length!=0){
                dataParam.push({"name": "ids", "value": rows.join()});
            }
            $.modal.loading("正在导出数据，请稍后...");
            $.post(table.options.exportUrl, dataParam, function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }
    var options;
    function query() {
        if(options!=null&&options!=undefined){
            var params = $("#bootstrap-table").bootstrapTable('getOptions');
            $("#bootstrap-table").bootstrapTable('refresh', params);
        }else{
            options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/import",
            importTemplateUrl: prefix + "/importTemplate",
            uniqueId:"ecId",
            modalName: "用工合同",
            columns: [{
                checkbox: true
            },
                {
                    field: 'ecId',
                    title: '合同编号',
                    visible: false
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'department',
                    title: '部门'
                },
                {
                    field: 'post',
                    title: '职务'
                },
                {
                    field: 'contractType',
                    title: '合同类型',
                    formatter: function(value, row, index) {
                        if(row.contractType=="1"){
                            return '<span class="label label-primary">劳动合同</span>';
                        }else if(row.contractType=="2"){
                            return '<span class="label label-success">劳动协议</span>';
                        }else if(row.contractType=="3"){
                            return '<span class="label label-success">聘用协议</span>';
                        }
                    }
                },
                {
                    field: 'startTime',
                    title: '起始日期'
                },
                {
                    field: 'endTime',
                    title: '结束日期'
                },
                {
                    field: 'fileCount',
                    title: '附件数'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if(row.status=="1"){
                            return '<span class="label label-primary">正常</span>';
                        }else if(row.status=="2"){
                            return '<span class="label label-warning">到期</span>';
                        }else if(row.status=="3"){
                            return '<span class="label label-warning">终止</span>';
                        }
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                }]
        };
        $.table.init(options);
        }
    }
</script>
</body>

<!-- 导入区域 -->

<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs" shiro:hasPermission="hrm:employmentContract:template"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！！！
            </font>
        </div>
    </form>
</script>
</html>